<?php
    //pre 5.3 singleton interface. LSB safe.

    abstract class singleton {
        function & static_call($class, $name, $value = null)
        {
            if (is_object($class))
            {
                $class = get_class($class);
            }
            elseif ( ! is_string($class))
            {
                throw new Core_Exception('Must be given an object or a class name', NULL);
            }

            $class = new ReflectionClass($class);
            if (!$value){
                return $class->getStaticPropertyValue($name);
            }else{
                $class->setStaticPorpertyValue($name, $value);
            }

        }

        public function instance($class) {
           
            $instance = self::static_call($class, "instance");
            if (!$instance instanceof $class) {
                $instance = new $class();
                self::static_call($class, "instance", $instance);
            }
            return $instance;
        }

    }

?>